package com.ddstation.common.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ddstation.master.entity.MaDataDictionaryEntity;
import com.ddstation.master.mapper.MaDataDictionaryMapper;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.spring.annotation.MapperScan;

@Service @Lazy
@MapperScan("com.ddstation.master.mapper")
public class DataDictionaryServiceImpl implements DataDictionaryService {
	//数据字典数据取得
	@Override
	@Transactional(readOnly=true)
	public List<MaDataDictionaryEntity> getCodeList(String codeKey){
		
		List<MaDataDictionaryEntity> list = maDataDictionaryMapper.selectByCategoryId(codeKey);
		if ( list == null || list.size()==0 ){
			throw new RuntimeException("ma_data_dictionary表中无["+codeKey+"]数据，请设置！");
		}
		
		return list;
	}

	@Override
	public List<MaDataDictionaryEntity> getMaDataDictoryByEntity(String codeKey,List<String> values) {
		Example example = new Example(MaDataDictionaryEntity.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("codeCategoryId",codeKey);
		criteria.andIn("value",values);
		return maDataDictionaryMapper.selectByExample(example);
	}

	@Inject private MaDataDictionaryMapper maDataDictionaryMapper;
}